

#ifndef __CL_MEMORY_POOL__H
#define __CL_MEMORY_POOL__H

#include <EGL/egl.h>
#include <GLES3/gl3.h>
#include <GLES3/gl32.h>
#include <map>
#include <vector>
#include "common/common.h"
#include "common/define.h"
#include "common/log.h"
#include "opencl_runtime.h"

namespace PanNN {
namespace OpenCL {
class CLMemeoryPool {
   public:
    CLMemeoryPool(const OpenCLRuntime *openCLRt);
    ~CLMemeoryPool();

    cl::Buffer *CLCreateBuffer(size_t size, cl_mem_flags flags, void *hostData = nullptr);
    ErrorCode CopyDeviceBufferToHost(cl::Buffer *bufferID, void *hostData, size_t size);
    ErrorCode CopyHostToDeviceBuffer(void *hostData, cl::Buffer *bufferID, size_t size);

    cl::Image2D *CLCreateImage(int w, int h, int c, cl_mem_flags flags, void *hostData = nullptr);
    ErrorCode CopyHostToDeviceImage(void *hostData, cl::Image2D *imageID, const std::vector<size_t> &region,
                                    size_t size);
    ErrorCode CopyDeviceImageToHost(void *hostData, cl::Image2D *imageID, const std::vector<size_t> &region,
                                    size_t size);
    // ErrorCode CopyDeviceImageToBuffer(GLuint textureID, GLuint ssboBufferID);
    // ErrorCode CopyDeviceBufferToImage(GLuint ssboBufferID, GLuint textureID);

    // GLuint CopyHostToDeviceImage(void *hostData, int width, int height, int channel);
    // void *CopyDeviceImageToHost(GLuint textureID);

    const OpenCLRuntime *m_openCLRt;

    // // key : ssboId, value : (size, type)
    // std::map<GLuint, std::pair<GLsizeiptr, GLenum>> m_ssboPool;

    // // key : texture, value : (textrueFormat, target)
    // std::map<GLuint, std::pair<std::vector<int>, std::vector<GLenum>>> m_texturePool;
};
}  // namespace OpenCL
}  // namespace PanNN
#endif  // __GL_MEMORY_POOL__H
